#include "EMT.h"

void EMT_component::control(double simulation_time)
{
    this->simulation_time = simulation_time;
    dab.setSig(1, 0, 0, 1, 1, 0, 0, 1);
    dab.control();
    vsource.control(simulation_time);
}

void EMT_component::begin(param &Params)
{
    brs.generate_A();
    get_num_node();
    get_num_br();

    dab.name = "dab";
    vsource.name = "vsource";
    rload.name = "rload";
    rGND1.name = "rGND1";
    rGND2.name = "rGND2";

    add_comp(&dab, &vsource, &rload, &rGND1, &rGND2);

    param vsourceParams;
    vsourceParams["Vamp"] = Params["vsource_Vamp"];
    vsourceParams["r"] = Params["vsource_r"];
    vsourceParams["vtype"] = Params["vsource_type"];
    vsource.set(vsourceParams);

    rload.R = Params["Rload"];
    rGND1.R = Params["rGND1"];
    rGND2.R = Params["rGND2"];

    dab.begin(Params);

    V.setZero(num_node - 1, 1);
    V_last_iteration = V;
    J.setZero(num_node - 1, 1);
    Yg.setZero(num_br, num_br);
}

void EMT_component::dsout_out_iteration()
{
    dab.dsout_out_iteration();
}
void EMT_component::dsout_in_iteration()
{
    dab.dsout_in_iteration();
}

void EMT_component::dsdyn_out_iteration(double delt, double simulaiton_time)
{
    this->delt = delt;
    this->simulation_time = simulaiton_time;

    dab.dsdyn_out_iteration(delt, simulation_time);

}

void EMT_component::dsdyn_in_iteration(double delt, double simulation_time)
{
    dab.dsdyn_in_iteration();
}